﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_GetMyApproved]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_GetMyApproved];
GO
CREATE PROCEDURE [dbo].[sproc_GetMyApproved] 
    @UserName nvarchar(300),
    @RightCode int =2,
    @Inherit bit =0
/*

============================================================
功能:    得到用户未审批文档
参数:
    @UserName nvarchar(300)    :    用户姓名
    @RightCode int =2        :    审批权限代号
============================================================

*/
AS
SET NOCOUNT ON

--得到用户名有审批权的CLASSID表
CREATE TABLE #CLASS (ClassID INT)

INSERT INTO #CLASS EXEC sproc_GetAllClassToAccess @UserName,@RightCode,@Inherit

IF EXISTS(SELECT 1 FROM #class WHERE ClassID =0) 
BEGIN
    SELECT a.*,b.classname 
        FROM 
            uds_document a,
            uds_class b 
        WHERE         a.classid = b.classid 
            and a.docdeletion =0 
            and a.doctype =0 
            and docapproved=0 
        ORDER BY a.DocAddedDate DESC    
    PRINT '全局'
    RETURN 
END

--得到所有的未审批文档
Select a.*,b.classname 
    FROM uds_document a,uds_class b 
    WHERE a.classid = b.classid and 
         a.ClassID IN (
                SELECT ClassID 
                FROM #CLASS
                ) and 
         a.docdeletion =0 and 
         a.doctype =0 and 
         a.docapproved=0 
    ORDER BY    a.DocAddedDate DESC

DROP TABLE #CLASS
SET NOCOUNT OFF